package com.whisperarts.financer.adapters;

import java.util.ArrayList;
import java.util.List;

import com.whisperarts.financer.dao.AccountsDAO;
import com.whisperarts.financer.model.account.Account;
import com.whisperarts.financer.model.account.AccountsCategory;

public class AccountAdapter {
	private final List<Account> accounts;
	private final String[] accountNames;
	
	public AccountAdapter() {
		accounts = new ArrayList<Account>();		
		for (AccountsCategory aCategory : AccountsDAO.getAccountsCategories()) {
			for (Account account : aCategory.getAccounts()) {
				accounts.add(account);
			}
		}
		accountNames = new String[accounts.size()];
		for (int i = 0; i < accounts.size(); i++) {
			accountNames[i] = accounts.get(i).getName();
		}
	}

	public String[] getAccountNames() {
		return accountNames;
	}

	public Account getAccountByPosition(int position) {
		return accounts.get(position);
	}

	public int getAccountPosition(Account account) {
		return accounts.indexOf(account);
	}
}
